package com.hospital.hospitalsystem.modules.user.controller;

import com.hospital.hospitalsystem.base.BaseResponse;
import com.hospital.hospitalsystem.base.PageData;
import com.hospital.hospitalsystem.config.TokenVerify;
import com.hospital.hospitalsystem.modules.user.biz.ShoppingCartBiz;
import com.hospital.hospitalsystem.modules.user.dto.BuyAndDeleteReq;
import com.hospital.hospitalsystem.modules.user.dto.ShoppingCartListReq;
import com.hospital.hospitalsystem.modules.user.dto.ShoppingCartReq;
import com.hospital.hospitalsystem.modules.user.dto.ShoppingCartRsp;
import com.hospital.hospitalsystem.utils.LoginUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author qiancheng@cqxyy.net
 * @date 2023/4/1
 */
@RestController
@RequestMapping("/shopping-cart")
@Api(tags = "购物车管理")
@Validated
public class ShoppingCartController {

    @Autowired
    private ShoppingCartBiz shoppingCartBiz;

    @Autowired
    private LoginUtils loginUtils;

    @ApiOperation(value = "用户填写药品进购物车")
    @RequestMapping(path = "/add",method = RequestMethod.POST)
    @TokenVerify(type = "user")
    public BaseResponse addMedical(@RequestBody ShoppingCartReq req){
        req.setUserUuid(loginUtils.getUser().getUserUuid());
        shoppingCartBiz.addMedical(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "用户修改购物车商品数量")
    @RequestMapping(path = "/change",method = RequestMethod.POST)
    @TokenVerify(type = "user")
    public BaseResponse changeMedical(@RequestBody ShoppingCartReq req){
        req.setUserUuid(loginUtils.getUser().getUserUuid());
        shoppingCartBiz.changeMedical(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "用户删除购物车物品")
    @RequestMapping(path = "/delete",method = RequestMethod.POST)
    @TokenVerify(type = "user")
    public BaseResponse deleteMedical(@RequestBody BuyAndDeleteReq req){
        req.setUserUuid(loginUtils.getUser().getUserUuid());
        shoppingCartBiz.deleteMedical(req);
        return BaseResponse.success();
    };
    @ApiOperation(value = "用户获取购物车物品")
    @RequestMapping(path = "/get",method = RequestMethod.POST)
    @TokenVerify(type = "user")
    public BaseResponse<PageData<ShoppingCartRsp>> getMedicalList(@RequestBody ShoppingCartListReq req){
        req.setUserUuid(loginUtils.getUser().getUserUuid());
        PageData<ShoppingCartRsp> result = shoppingCartBiz.getMedicalList(req);
        return BaseResponse.success(result);
    };
}
